var app = getApp(), Toast = require("../../libs/zanui/toast/toast");

Page({
    data: {
        indicatorDots: !0,
        noticeDots: !1,
        autoplay: !0,
        interval: 3e3,
        duration: 500,
        vertical: !0,
        slid:[
             {
                  img:'../../libs/images/tt.jpg'
             },
             {
                  img: '../../libs/images/gugu.png'
             }
        ],
         categor:[{
              cover:'../../libs/images/cc.png',
              title:'领养小鸡'
         },{
                   cover:'../../libs/images/xt.png',
            title:'领养小兔'
         },
         {
              cover: '../../libs/images/nn.png',
              title: '领养小牛'
         },
         {
              cover:'../../libs/images/other.png' ,
              title:'其它'
         }],
        display: [ {
            id: 0,
            title: "默认排序"
        }, {
            id: 1,
            title: "离我最近"
        }, {
            id: 2,
            title: "人气最高"
        } ],
        selectedId: 0,
        fixed: !0,
        height: 35,
        pages: 1,
        hide: !0,
        more: !0,
        refresh: !0
    },
    onLoad: function() {
        app.viewCount(), app.util.footer(this), this.getIndexData();
    },
    getIndexData: function() {
        var t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", e = this;
        app.util.request({
            url: "entry/wxapp/home",
            cachetime: "0",
            data: {
                kw: t,
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) e.showIconToast(t.errmsg); else {
                    var a = t.data.data.items;
                    e.setData({
                        slide: t.data.data.slide,
                        category: t.data.data.category,
                        notice: t.data.data.notice
                    }), setTimeout(function() {
                        e.setData({
                            list: a,
                            total: a.length
                        });
                    }, 1e3);
                }
            }
        });
    },
    doSearch: function(t) {
        var e = this, a = t.detail.value;
        e.setData({
            keyword: a
        }), app.util.request({
            url: "entry/wxapp/home",
            cachetime: "0",
            data: {
                kw: a,
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) e.showIconToast(t.errmsg); else {
                    var a = t.data.data.items;
                    e.setData({
                        selectedId: 0,
                        list: a,
                        total: a.length
                    });
                }
            }
        });
    },
    toMimipg: function(t) {
        var a = t.currentTarget.dataset.appid, e = t.currentTarget.dataset.path;
        wx.navigateToMiniProgram({
            appId: a,
            path: e,
            success: function(t) {
                console.log("打开成功");
            }
        });
    },
    closeModal: function() {
        this.setData({
            showAuth: !1
        });
    },
    handleTabChange: function(t) {
        var s = this, a = t.detail, o = s.data.keyword;
        o || (o = ""), s.setData({
            selectedId: a,
            pages: 1,
            more: !0,
            refresh: !0
        }), 0 == a ? s.getIndexData(o) : 1 == a ? (wx.getSetting({
            success: function(t) {
                var a = t.authSetting["scope.userLocation"];
                "undefined" != a && !1 === a && s.setData({
                    showAuth: !0
                });
            }
        }), wx.getLocation({
            type: "gcj02",
            success: function(t) {
                var a = t.latitude, e = t.longitude;
                s.setData({
                    lat: a,
                    lng: e
                }), app.util.request({
                    url: "entry/wxapp/home",
                    cachetime: "0",
                    data: {
                        lat: a,
                        lng: e,
                        op: "location",
                        kw: o,
                        m: "superman_hand2"
                    },
                    success: function(t) {
                        if (t.data.errno) s.showIconToast(t.errmsg); else {
                            var a = t.data.data.items;
                            s.setData({
                                list: a,
                                total: a.length
                            });
                        }
                    }
                });
            }
        })) : app.util.request({
            url: "entry/wxapp/home",
            cachetime: "0",
            data: {
                op: "popular",
                kw: o,
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) s.showIconToast(t.errmsg); else {
                    var a = t.data.data.items;
                    s.setData({
                        list: a,
                        total: a.length
                    });
                }
            }
        });
    },
    onReachBottom: function() {
        var s = this;
        if (s.data.refresh) if (s.data.total < 10) s.setData({
            more: !1
        }); else {
            s.setData({
                hide: !1
            });
            var o = s.data.pages + 1, t = "", a = "", e = "", n = "";
            s.data.keyword && (n = s.data.keyword), 1 == s.data.selectedId ? (t = "location", 
            a = s.data.lat, e = s.data.lng) : 2 == s.data.selectedId && (t = "popular"), app.util.request({
                url: "entry/wxapp/home",
                cachetime: "0",
                data: {
                    page: o,
                    op: t,
                    lat: a,
                    lng: e,
                    kw: n,
                    m: "superman_hand2"
                },
                success: function(t) {
                    if (s.setData({
                        hide: !0
                    }), 0 == t.data.errno) {
                        var a = t.data.data.items;
                        if (0 < a.length) {
                            var e = s.data.list.concat(a);
                            s.setData({
                                total: a.length,
                                list: e,
                                pages: o
                            });
                        } else s.setData({
                            more: !1,
                            refresh: !1
                        });
                    } else s.showIconToast(t.errmsg);
                }
            });
        }
    },
    onPullDownRefresh: function() {
        this.getIndexData(), wx.stopPullDownRefresh();
    },
    onShareAppMessage: function() {
        return {
            path: "/pages/home/index"
        };
    },
    showIconToast: function(t) {
        var a = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "fail";
        Toast({
            type: a,
            message: t,
            selector: "#zan-toast"
        });
    }
});